<?php

	if($_GET['operation']=="add" or $_GET['operation']=="edit")
	{
		if($_POST['act'])
		{	
			unset($_GET['operation']);
			unset($_GET['s']);
			unset($_GET['m']);
			$param = $_POST;
			$param['add_time'] = time();
			//添加
			if($_POST["act"]=='save')
			{
				if(empty($param['city_name'])){
					admin_msg("module.php?m=product&s=order_since.php","城市名称不能为空");
					return false;
				}
				$time = time();
				$db->query("insert into ".SINCE." (`city_name`,`address`,`b_hours`,`statu`,`add_at`) values
				('{$param['city_name']}','{$param['address']}','{$param['b_hours']}','{$param['statu']}','$time')" );
				$last_id = $db->lastid();
				if($last_id){
					admin_msg("module.php?m=product&s=order_since.php","添加成功");
					return false;
				} else {
					admin_msg("module.php?m=product&s=order_since.php","添加失败");
					return false;
				}
			}
			//修改
			if($_POST["act"]=='edit' and is_numeric($_POST['id']))
			{
				$sql = "update ".SINCE." set city_name = '{$param['city_name']}',statu = '{$param['statu']}',address='{$param['address']}',b_hours='{$param['b_hours']}' where id = '{$param['id']}'   ";
				if($db->query($sql)){
					msg("?m=product&s=order_since.php");
				} else {
					msg("?m=product&s=order_since.php",'修改失败');
				}

			}


		}

		if($_GET['editid'] and is_numeric($_GET['editid']))
		{
			$sql="select * from ".SINCE." where id='$_GET[editid]'";
			$db->query($sql);
			$re=$db->fetchRow();
			$tpl->assign("re",$re);
		}

	}
	else
	{
		if($_GET['delid'])
		{
			$sql="delete from ".SINCE."  where id like '$_GET[delid]%' ";
			$db->query($sql);
			msg("?m=product&s=order_since.php");
		}

		$sql = "select * from ".SINCE." where 1 order by id desc";
		$db->query($sql);
		$de = $db->getRows();

	}
	$tpl->assign("de",$de);
	$tpl->display("order_since.htm");
?>